import { createRouter, createWebHashHistory } from 'vue-router'
import App from '@/App.vue'
import { getToken, LOCAL_WX } from "../utils/user"

// 路由规则
const routes = [
  {
    path: '/',
    component: App,
    children: [
      { path: '', redirect: '/login' },
      {
        path: '/login/:id?',
        name: 'login',
        component: () => import('@/views/Login.vue')
      },
      {
        path: '/index/',
        name: 'index',
        component: () => import('@/views/Index.vue')
      },
      {
        path: '/DangAn/',
        name: 'DangAn',
        component: () => import('@/views/DangAn.vue')
      },
      {
        path: '/DangAnCreate/',
        name: 'DangAnCreate',
        component: () => import('@/views/DangAnCreate.vue')
      },
      {
        path: '/DangAnDetail/',
        name: 'DangAnDetail',
        component: () => import('@/views/DangAnDetail.vue')
      },
      {
        path: '/DangAnHeath/',
        name: 'DangAnHeath',
        component: () => import('@/views/DangAnHeath.vue')
      },
      {
        path: '/DangAnEdit/',
        name: 'DangAnEdit',
        component: () => import('@/views/DangAnEdit.vue')
      },
      {
        path: '/FuWu/',
        name: 'FuWu',
        component: () => import('@/views/FuWu.vue')
      },
      {
        path: '/FuWuCreate/',
        name: 'FuWuCreate',
        component: () => import('@/views/FuWuCreate.vue')
      },
      {
        path: '/FuWuDetail/',
        name: 'FuWuDetail',
        component: () => import('@/views/FuWuDetail.vue')
      },
      {
        path: '/FuWuHistory/',
        name: 'FuWuHistory',
        component: () => import('@/views/FuWuHistory.vue')
      },
      {
        path: '/FuWuList/',
        name: 'FuWuList',
        component: () => import('@/views/FuWuList.vue')
      },
      {
        path: '/FuWuResult/',
        name: 'FuWuResult',
        component: () => import('@/views/FuWuResult.vue')
      },
      {
        path: '/FuWuWait/',
        name: 'FuWuWait',
        component: () => import('@/views/FuWuWait.vue')
      },

      {
        path: '/Message/',
        name: 'Message',
        component: () => import('@/views/Message.vue')
      },
      {
        path: '/MessageChat/',
        name: 'MessageChat',
        component: () => import('@/views/MessageChat.vue')
      },
      {
        path: '/MessageFuWu/',
        name: 'MessageFuWu',
        component: () => import('@/views/MessageFuWu.vue')
      },
      {
        path: '/MessageSystem/',
        name: 'MessageSystem',
        component: () => import('@/views/MessageSystem.vue')
      },
      {
        path: '/QianYue/',
        name: 'QianYue',
        component: () => import('@/views/QianYue.vue')
      },
      {
        path: '/QianYueCreate/',
        name: 'QianYueCreate',
        component: () => import('@/views/QianYueCreate.vue')
      },
      {
        path: '/QianYueDetail/',
        name: 'QianYueDetail',
        component: () => import('@/views/QianYueDetail.vue')
      },
      {
        path: '/QianYueResult/',
        name: 'QianYueResult',
        component: () => import('@/views/QianYueResult.vue')
      },
      {
        path: '/QianYueWait/',
        name: 'QianYueWait',
        component: () => import('@/views/QianYueWait.vue')
      },
      {
        path: '/Tag/',
        name: 'Tag',
        component: () => import('@/views/Tag.vue')
      },
      {
        path: '/TagCreate/',
        name: 'TagCreate',
        component: () => import('@/views/TagCreate.vue')
      },
      {
        path: '/TagName/',
        name: 'TagName',
        component: () => import('@/views/TagName.vue')
      },
      {
        path: '/TagItem/',
        name: 'TagItem',
        component: () => import('@/views/TagItem.vue')
      },
      {
        path: '/TeamInsert/',
        name: 'TeamInsert',
        component: () => import('@/views/TeamInsert.vue')
      },
      {
        path: '/TeamMy/',
        name: 'TeamMy',
        component: () => import('@/views/TeamMy.vue')
      },
      {
        path: '/TeamSearch/',
        name: 'TeamSearch',
        component: () => import('@/views/TeamSearch.vue')
      },
      {
        path: '/User/',
        name: 'User',
        component: () => import('@/views/User.vue')
      },
      {
        path: '/UserEdit/',
        name: 'UserEdit',
        component: () => import('@/views/UserEdit.vue')
      },
      {
        path: '/UserPassWord/',
        name: 'UserPassWord',
        component: () => import('@/views/UserPassWord.vue')
      },
      {
        path: '/UserSet/',
        name: 'UserSet',
        component: () => import('@/views/UserSet.vue')
      },
    ]
  }
]

const router = createRouter({
  // vueRouter@3版本的mode改成了history，hash模式配置createWebHashHistory，history模式配置createWebHistory
  history: createWebHashHistory(),
  routes
})


router.beforeEach((to, from, next) => {
  // const token = getToken();

  // if (!token && to.path !== '/login') {
  //   let checkWx = localStorage.getItem(LOCAL_WX)
  //   if (!checkWx) {
  //     next('/login');
  //   } else {
  //     //微信登录
  //     next()
  //   }
  // } else {
  //   next();
  // }

  next()
});

export default router